const emptyObj = {};



export default class TKY {
  constructor(params) {
    /// 登录需要参数
    /// hotLine 热线号码 否
    /// cno 座席账号 是 以开通账号为准
    /// pwd 座席账号密码 是 以开通账号密码为准
    /// bindTel 绑定硬件话机号码 是 以开通硬件分机账号为准
    /// bindType 绑定类型 是 1:电话号码;2:分机号码;3:软电话
    /// initStatus 初始化状态 是 online :空闲;pause:置忙
    /// baseUrl 连接服务器http地址(https) 是 https:///cc.ketianyun.com 或者其他



    this.params = params;
    /// 坐席状态回调状态
      /// ready 空闲 {eventName: 'ready'}
      /// notready 未就绪 {eventName: 'notready'}
      /// busy 忙碌 {eventName: 'busy'}
      /// outRinging 外呼振 铃 {eventName: 'outRinging', name: 'ringing', customerNumber: '来电号 码', uniqueId:'callid'}
      /// comeRinging 来电振 铃 {eventName: 'comeRinging', name: 'ringing', customerNumber: '被叫号 码', uniqueId:'callid'}
      /// answered 通话中 {eventName: 'answer'}
      /// onlineUnlink 挂机后 空闲 {eventName: 'onlineUnlink'}
      /// pauseUnlink 挂机后 忙碌 {eventName: 'pauseUnlink'}
      /// hold 保持 {eventName: 'hold'}
  }
  login = () => { /// 登录
    window.cbLogin = window.__TKYCallback;
    window.executeAction('doLogin', this.params);
    /// 登录回调状态
      /// code 0:成功;1:失败
      /// msg 成功或失败的原因
      /// hotline 热线号码
      /// enterpriseId 企业id
      /// cno 坐席号
      /// cname 坐席名称
      /// bindTel 绑定号码
  }
  logout = () => { /// 登出
    window.cbLogout = window.__TKYCallback;
    window.executeAction('doLogout', { type: '1' });
    /// 登出回调状态
      /// code 0:成功;1:失败;2:未登录
      /// msg 原因
      /// enterpriseId
      /// cno
  }
  callout = (number) => { /// 外呼
    window.cbPreviewOutCall = window.__TKYCallback;
    window.executeAction('doPreviewOutCall', { tel: number, callType: '3' });
    /// 外呼回调状态
      /// code 0:成功;6:失败原因
      /// msg 原因
  }
  hold = () => { /// 保持
    window.cbHold = window.__TKYCallback;
    window.executeAction('doHold', emptyObj);
    /// 保持回调状态
      /// code 0:成功;17:失败
  }
  unhold = () => { /// 取消保持
    window.cbUnhold = window.__TKYCallback;
    window.executeAction('doUnhold', emptyObj);
    /// 保持取消回调状态
      /// code 0:成功;18:失败
  }
  hangup = () => { /// 挂机
    window.cbUnLink = window.__TKYCallback;
    window.executeAction('doUnLink', emptyObj);
    /// 挂机回调状态
      /// code 0:成功;2:失败
  }
  transfer = (number) => { /// 转接
    window.cbTransfer = window.__TKYCallback;
    var params = {};
    params.transferObject = number;
    window.executeAction('doTransfer', params);
    /// 转接回调状态
      /// code 0:成功;24:失败
  }
}
